package com.totoro.mysql;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class BachExecuteTest {
    public static void test() throws SQLException {
        long begin = System.currentTimeMillis() ;
        String sql = "INSERT INTO test_table (name) values(?)" ;
        Connection connection = ConnectionUtil.getConnection() ;
        PreparedStatement preparedStatement = connection.prepareStatement(sql) ;
        for(int i=0; i<10000; i++){
            preparedStatement.setString(1,"2name"+i);
            preparedStatement.addBatch();
        }

        preparedStatement.executeBatch();
        connection.commit();
        connection.close();
        long end = System.currentTimeMillis() ;
        System.out.println("方法共用时:"+(end-begin)+"毫秒！");
    }

    public static void main(String[] args) {
        try {
//            test();
            testOtherDb();
        } catch (SQLException e) {
            e.printStackTrace();
        }



    }

    public static void testOtherDb() throws SQLException {
        String sql = "INSERT INTO school.school (name,code) values(?,?)" ;
        Connection connection = ConnectionUtil.getConnection() ;
        PreparedStatement preparedStatement = connection.prepareStatement(sql) ;
        preparedStatement.setString(1,"都昌二中");
        preparedStatement.setString(2,"DC2");
        preparedStatement.execute();
        connection.commit();
        connection.close();
    }
}
